<template>
  <div align="center">
    <h2>新增优惠券</h2>
    <table border="1">
      <tr>
        <td>优惠券名称</td>
        <td>
          <input type="text" v-model="state.dname">
        </td>
      </tr>
      <tr>
        <td>优惠券金额</td>
        <td>
          <input type="text" v-model="state.dprice">
        </td>
      </tr>
      <tr>
        <td>折扣</td>
        <td>
          <input type="text" v-model="state.dzhekou">
        </td>
      </tr>
      <tr>
        <td>优惠券数量</td>
        <td>
          <input type="text" v-model="state.dnum">
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
          <input type="button" value="增加" @click="add">
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive,toRefs } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
let router = useRouter()

let data = reactive({
  state:{
    dname:'',
    dprice:'',
    dzhekou:'',
    dnum:'',
  },
})
let {state} = toRefs(data)

const add =()=>{
  axios({
    url:'/api/Store/PostDiscountAdd',
    method:'post',
    data:state.value
  })
  .then(res=>{
    console.log(res)
    if(res.data.data > 0){
      alert("优惠券添加成功");
      router.push('/storelist')
    }
    else if(res.data.data == -1){
      return alert("优惠券已存在")
    }
    else{
      alert("优惠券添加失败");
      return;
    }
  })
  .catch(err=>{
    console.log(err)
  })
}
</script>

<style scoped>

</style>